<script type="text/javascript">
$(document).ready(function()
		{
	/////check cua hh
						$(".checkboxhh").click(function()
						{
							if ($(this).is(":checked"))
							{
								id=$(this).attr('id');
								$('.tblhh td#'+id).css('background-color','#CCFFCC');
					
							}
							else
							{
								id=$(this).attr('id');
								$('.tblhh td#'+id).css('background-color','');
							}
						});
	
						$("#selectallhh").click(function(){
											$(".checkboxhh").prop('checked',true);
											$('.tblhh td').css('background-color','#CCFFCC');
												});
							
						$("#unselectallhh").click(function(){
											$(".checkboxhh").prop('checked',false);
											$('.tblhh td').css('background-color','');
												});
			/////check cua nv
						$(".checkboxnv").click(function()
								{
									if ($(this).is(":checked"))
									{
										id=$(this).attr('id');
										$('.tblnv td#'+id).css('background-color','#CCFFCC');
							
									}
									else
									{
										id=$(this).attr('id');
										$('.tblnv td#'+id).css('background-color','');
									}
								});
			
								$("#selectallnv").click(function(){
													$(".checkboxnv").prop('checked',true);
													$('.tblnv td').css('background-color','#CCFFCC');
														});
									
								$("#unselectallnv").click(function(){
													$(".checkboxnv").prop('checked',false);
													$('.tblnv td').css('background-color','');
														});
		});

	function validate()
	{
		$checkedhh=0;
		$checkednv=0;
		//$numpro=parseInt($("#countcheck").val(),10);
		$("input:checkbox").each(function(){
											if ($(this).is(":checked"))
											{
												if ($(this).attr('class')=='checkboxhh')
													$checkedhh++;
												else
													$checkednv++;
											}
											});
		if ($checkedhh==0)
		{
			alert("Bạn chưa chọn sản phẩm nào");
			return false;			
		}
		if ($checkednv==0)
		{
			alert("Bạn chưa chọn Nhân Viên");
			return false;			
		}
		return true;
	}
</script>

<div class="index" style="margin-top: 20px;">

<?php
	echo $this->Form->create('Chitieunv', array('url'=>array('controller'=>'chitieunvs','action' => 'themchitieu',$kehoach_id,$themchitieu),'type'=>'post','onsubmit'=>'return validate()'));
	echo "<fieldset>";
	
		echo "<legend>Chỉ Tiêu</legend>";
		if(isset($col_ctdv) && isset($row_ctdv) && isset($datadv) && isset($datadc))
		{	
			echo "<h3>Chỉ Tiêu Của Trung Tâm:</h3>";
			echo $ctable->show_2_table($col_dc,$col_ctdv,$row_ctdv,$datadc,$datadv); 
		}
		else 
		{
			echo "<h2>Chưa Có Kế Hoạch Tháng Này</h2>";
		}
		//echo $form->input('thang',array('id'=>'thang','label'=>'Tháng','options'=>$thoigian,'empty'=>"Chọn Tháng"));
		echo "<div id='khtt'></div>";
		echo "</fieldset>";
		echo $form->hidden('checknumhh',array('value'=>"0",'id'=>'checknumhh'));
		echo $form->hidden('checknumnv',array('value'=>"0",'id'=>'checknumnv'));
		echo $form->hidden('countcheckhh',array('value'=>count($hanghoas),'id'=>'countcheckhh'));
		echo $form->hidden('countchecknv',array('value'=>count($nhanvien),'id'=>'countchecknv'));
		echo $form->hidden('kehoach_id',array('value'=>$kehoach_id));
		$i=0;
		
		
		//// chi tieu
		echo "<a name='hangh'></a>";
		echo "<fieldset>";
		echo "<legend>Chọn Chỉ Tiêu</legend>";
		$counthh = count($hanghoas);
		echo "<table class='tblhh' id='tables'>";
		foreach ($hanghoas as $hh_id => $tenhh):
			if ($i%2==0)
				echo "<tr>";
				//$form->input('checkboxhh'.$i,array('class'=>'checkboxhh','id'=>'checkboxhh'.$i,'type'=>'checkbox','id'=>'checkbox'.$i,'value'=>$hh_id,'hidden'=>False,'label'=>$tenhh));
				$ch = array_key_exists($hh_id, $hanghoa);
				$backg= $ch ? 'bgcolor="#CCFFCC"' :'';
			echo "<td id='checkboxhh".$i."' " . $backg . " >".$form->checkbox('checkboxhh'.$i,array('class'=>'checkboxhh','id'=>'checkboxhh'.$i,'value'=>$hh_id,'hidden'=>False, 'checked'=>$ch?true:false));
			echo $form->hidden('',array('value'=>$tenhh,'name'=>'data[Chitieunv][hh]['.$hh_id.']'));
			echo $this->Form->label('',$tenhh)."</td>";
			if ($i%2!=0)
				echo "</tr>";
			$i++;
		endforeach;
		echo "</table>";
		echo "<a href='#hangh' id='selectallhh'>Chọn Tất Cả</a> / <a href='#hangh' id='unselectallhh'>Bỏ Chọn Tất Cả</a>";
		echo "</fieldset>";
		
		//// nhan vien
		echo "<a name='nhanv'></a>";
		echo "<fieldset>";
		echo "<legend>Chọn Nhân Viên</legend>";
		$i=0;
		echo "<table class='tblnv' id='tables'>";
		foreach ($nhanvien as $nv_id => $tennv):
			if ($i%2==0)
				echo "<tr>";
			echo "<td id='checkboxnv".$i."'>".$form->checkbox('checkboxnv'.$i,array('class'=>'checkboxnv','id'=>'checkboxnv'.$i,'value'=>$nv_id,'hidden'=>False));
			echo $form->hidden($nv_id,array('value'=>$tennv));
			echo $this->Form->label('',$tennv)."</td>";
			if ($i%2!=0)
				echo "</tr>";
			$i++;
		endforeach;
		echo "</table>";
		echo "<a href='#nhanv' id='selectallnv'>Chọn Tất Cả</a> / <a href='#nhanv' id='unselectallnv'>Bỏ Chọn Tất Cả</a>";
		echo "</fieldset>";
?>


<?php
	$this->Js->get('#thang')->event('change',
								$this->Js->request(array('controller' => 'chitieunvs', 'action' => 'laykhtt'),
								array('update' => '#khtt','async' => true,
								'dataExpression' => true,'method' => 'post',
								'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

 echo $this->Form->end('Lập Chỉ Tiêu',false);
 ?>

</div>